import inspect
import sys
from datetime import datetime
from functools import wraps


def logging(logfile="out.log"):
    def logging_decorator(func):
        @wraps(func)
        def wrapped_function(*args, **kwargs):
            log = f"[{datetime.now()}] {func.__name__} was called"
            with open(logfile, "a") as log_f:
                log_f.write(log+"\n")
            return func(*args, **kwargs)
        return wrapped_function
    return logging_decorator

@logging()
def my_func1():
    print(f"{inspect.stack()[0][3]} 函数执行.....")

@logging(logfile="out2.log")
def my_func2():
    print(f"{sys._getframe().f_code.co_name} 函数执行.....")


if __name__ == '__main__':
    my_func1()
    my_func2()
